package com.manage.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.modules.domain.TBaseServicePhoto;
import com.manage.modules.mapper.TBaseServicePhotoMapper;
import com.manage.modules.service.ITBaseServicePhotoService;
import com.manage.modules.utils.UploadUtil;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 维护信息照片Service业务层处理
 *
 * @author xu
 * 2021/8/19 10:14
 */
@Service
public class TBaseServicePhotoServiceImpl extends ServiceImpl<TBaseServicePhotoMapper, TBaseServicePhoto> implements ITBaseServicePhotoService {

    @Override
    public void delete(List<TBaseServicePhoto> deletePhotoList) {
        if (deletePhotoList != null && deletePhotoList.size() > 0) {
            for (TBaseServicePhoto servicePhoto : deletePhotoList) {
                // 删除照片
                UploadUtil.delete(servicePhoto.getLocal());
                // 删除对象
                boolean b = removeById(servicePhoto.getServicePhotoId());
            }
        }

    }

    @Override
    public void deleteByServiceIds(Collection<Long> ids) {
        // 不存在或为空直接返回
        if (ids == null || ids.size() == 0) {
            return;
        }
        LambdaQueryWrapper<TBaseServicePhoto> lqw = Wrappers.lambdaQuery();
        lqw.in(true, TBaseServicePhoto::getServiceId, ids);
        List<TBaseServicePhoto> list = list(lqw);
        delete(list);
    }


    @Override
    public List<TBaseServicePhoto> findByServiceId(Long serviceId) {
        if (serviceId == null) {
            return null;
        }
        LambdaQueryWrapper<TBaseServicePhoto> lqw = Wrappers.lambdaQuery();
        lqw.eq(true, TBaseServicePhoto::getServiceId, serviceId);
        return list(lqw);
    }
}
